module.exports = () => {
  return async function(ctx, next) {
    let token = ctx.headers.authorization;
    token = token || null;
    if (!token) {
      ctx.throw(401, '请登录后再进行请求');
    }
    try {
      ctx.service.user.verifyToken(token);
    } catch (error) {
      ctx.throw(401, 'token已过期请重新登录');
    }
    await next();
  };
};
